/**
 * Created by FDG296 on 2017/9/30.
 */
$(document).ready(function(){
    $('#table_id_example').DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        "scrollY": "550px",
        "scrollCollapse": true,
        "scrollX": true,
        ajax:{
            url:'/goods/get-goods-list',
            type:'post',
            data:function(d){
                d.search_goods_name_cn = $('#search_goods_name_cn').val();
                d.goods_sku = $('#goods_sku').val();
                d.is_examine = $('#is_examine').val();
            },
            error:getError
        },
        aoColumns: [
            { "data": "", "bSortable": false},
            { "data": "id", "bSortable": false},
            { "data": "main_goods_id", "bSortable": false },
            { "data": "goods_name_cn", "bSortable": false },
            { "data": "category_step1_name", "bSortable": false },
            { "data": "category_step2_name", "bSortable": false },
            { "data": "tag_name", "bSortable": false },
            { "data": "brand_name", "bSortable": false },
            { "data": "sort", "bSortable": true },
            { "data": "id", "bSortable":false },
            { "data": "use_flg", "bSortable":false },
            { "data": "is_examine", "bSortable":false },
            { "data": "main_goods_id","sClass": "text-center", "bSortable": false}
        ],
        columnDefs: [
            {
                "targets": [0],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                	var html = '<a href="/goods/get-main-goods-detail?id='+full.id+'">修改</a>&nbsp;&nbsp;&nbsp;<a href="javascript:" onclick="modSku('+ full.id +')">规格</a>&nbsp;&nbsp;&nbsp;';
                    if(full.is_examine == '1'){
                    	html += '<br/><a href="javascript:" class="text-danger" onclick="goodsExamine('+ full.id +')">审核</a>&nbsp;&nbsp;&nbsp;';
                    }
                    var a_class = '';
                    if(full.sale_need_examine == 1){
                    	a_class = 'text-danger';
                    }
                    html += '<a href="javascript:" class="'+a_class+'" onclick="getSkuList('+ full.id +')">商品列表</a>';
                    return html;
                }
            },
            {
                "targets": [1],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                    return '<label><input class="publish_class" type="checkbox" name="publish_id[]" value="'+ full.id +'">&nbsp;&nbsp;' + full.id + '</label>';
                }
            },
            {
                "targets": [9],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                    return '<a href="/goods-match/goods-list/?type=4&id='+ data +'">商品搭配</a>';
                }
            },
            {
                "targets": [10],
                "data": "use_flg",
                "render": function(data, type, full) {
                	var use_flg = '';
                	if(data == 1){
                		use_flg = '上架';
                	}else if(data == 2){
                		use_flg = '上架已售罄';
                	}else{
                		use_flg = '下架';
                	}
                	return '<span class="text-primary">'+use_flg+'</span>';
                }
            },
            {
                "targets": [11],
                "data": "is_examine",
                "render": function(data, type, full) {
                    var status = '待审核';
                    var status_class = 'text-danger';
                    if(data == '2'){
                    	status = '核准';
                    	status_class = 'text-primary';
                    }else if(data == '3'){
                    	status = '核退';
                    	status_class = 'text-warning';
                    }
                    return '<span class="'+status_class+'">'+status+'</span>';
                }
            },
            {
                "targets": [12],
                "data": "is_examine",
                "render": function(data, type, full) {
                    return '<a href="/goods/goods-log?id='+data+'"><img src="/static/img/edit.png" style="height:25px;width:25px;"/></a>';
                }
            }
        ],
        order: [[ 7, "desc" ]]
    });

    $('#goods_id_example').DataTable({
        dom: '<"top">rt<"bottom"flip><"clear">',
        language: {
            "sUrl":'../static/plugins/datatables/language.json'
        },
        "searching": false,
        "processing": true,
        "serverSide": true,
        "aLengthMenu":[5,10,20],
        ajax:{
            url:'/goods/get-sku-list',
            type:'post',
            data:function(d){
                d.select_goods_id = $('#select_goods_id').val();
                d.search_goods_sku = $('#search_goods_sku').val();
            }
        },
        aoColumns: [
            { "data": "", "bSortable": false},
            { "data": "id", "bSortable": true},
            { "data": "goods_name_cn", "bSortable": false },
            { "data": "goods_id", "bSortable": false },
            { "data": "sku", "bSortable": false },
            { "data": "spec_val", "bSortable": false },
            { "data": "spec_color_val", "bSortable": false },
            { "data": "sort", "bSortable": true },
            { "data": "use_flg", "bSortable": true },
            { "data": "use_flg", "bSortable":false },
            { "data": "is_examine", "bSortable":false },
            { "data": "id", "bSortable": false},
        ],
        columnDefs: [
            {
                "targets": [0],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                    var html = '<a href="javascript:" onclick="updateGoodsSku(\''+ full.id +'\',this)">修改</a>';
                    if(full.is_examine == '1'){
                    	html += ' | <a href="javascript:" class="text-danger" onclick="examineGoodsSku('+ full.id +')">审核</a>';
                    }
                    return html;
                }
            },
            {
            	"targets": [5],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                	var html = '';
                	if(full.id == ''){
                		var goods_spec = full.goods_spec;
                		html += '<select disabled="disabled" class="form-control" name="spec_val">';
                		goods_spec[2].forEach(function(e,index){
                			var selected = e.spec_id == data ? 'selected' : '';
                			html += '<option value="'+e.spec_id+'" '+selected+'>'+e.spec_val+'</option>';
                		});
                        html += '</select>';
                	}else{
                		html += data;
                	}
                    return html;
                }
            },
            {
            	"targets": [6],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                	var html = '';
                	if(full.id == ''){
                		var goods_spec = full.goods_spec;
                		html += '<select disabled="disabled" class="form-control" name="spec_color_val">';
                		goods_spec[1].forEach(function(e,index){
                			var selected = e.spec_id == data ? 'selected' : '';
                			html += '<option value="'+e.spec_id+'" '+selected+'>'+e.spec_val+'</option>';
                		});
                        html += '</select>';
                	}else{
                		html += data;
                	}
                    return html;
                }
            },
            {
                "targets": [8],
                "orderable":false,
                "searchable":false,
                "render": function(data, type, full) {
                    if(data == ''){
                        return '--';
                    }else if(data == 1 || data == 0){
                    	if(data == 1){
                    		return '上架';
                    	}else{
                    		return '下架';
                    	}
                    }else{
                    	return '上架已售罄';
                    }
                }
            },
            {
                "targets": [9],
                "data": "use_flg",
                "render": function(data, type, full) {
//                    var html = '';
//                    if(data == ''){
//                    	html = '--';
//                    }else if(data == 1){
//                        html = '<a href="javascript:" onclick="changeGoodsStatus('+ full.id +',0)">下架</a>';
//                    }else{
//                        html = '<a href="javascript:" onclick="changeGoodsStatus('+ full.id +',1)">上架</a>';
//                    }
//                	return html;                	
                    return '<span class="switch" data-id="'+ full.id +'" data-flg="'+(data == 1 ? 0 : 1)+'"><input  style="width:20px;height:20px;" type="checkbox" '+(data == 1 ? 'checked="checked"' : '')+' class="input-check"></span>';
                    
                }
            },
            {
                "targets": [10],
                "data": "is_examine",
                "render": function(data, type, full) {
                	var status = '--';
                    if(data == '2'){
                    	status = '核准';
                    	status_class = 'text-primary';
                    }else if(data == '3'){
                    	status = '核退';
                    	status_class = 'text-warning';
                    }else if(data == '1'){
                    	var status = '待审核';
                        var status_class = 'text-danger';
                    }
                    return '<span class="'+status_class+'">'+status+'</span>';
                }
            },
            {
            	"targets": [11],
                "data": "is_examine",
                "render": function(data, type, full) {
                	var html = '<span>--</span>'
                    if(data == ''){
                    	html = '<a href="javascript:void(0);" class="text-danger del-line">删除</a>';
                    }
                    return html;
                }
            }
        ],
        order: [[ 1, "desc" ]]
    });
});

$('#checked_all').on('click',function(){
	var is_checked = $('.publish_class').prop('checked');
	if(is_checked == undefined){
		return false;
	}
	$('.publish_class').prop('checked',is_checked ? false : true)
});

$('table').on('click','.input-check',function(){
	var id = $(this).parent().attr('data-id');
	var use_flg = $(this).parent().attr('data-flg');
	changeGoodsStatus(id,use_flg);
});

$('#select_button').click(function(){
    table_list_reload();
})

$('#reset_button').click(function(){
    $('#search_goods_name_cn').val('');
    $('#goods_sku').val('');
    $('#is_examine').val(1);
    table_list_reload();
})

$('#select_goods_button').click(function(){
    goods_list_reload();
})

$('#reset_goods_button').click(function(){
    $('#search_goods_sku').val('');
    goods_list_reload();
})

//table刷新
function table_list_reload(){
    var table = $('#table_id_example').DataTable();
    table.ajax.reload();
}

function goods_list_reload(){
    var table = $('#goods_id_example').DataTable();
    table.ajax.reload();
}

function changeMainGoodsStatus(id,use_flg){
    var title = '';
    if(use_flg == 1){
        title = '确定上架吗？';
    }else if(use_flg == 0){
        title = '确定下架吗？';
    }else{
        title = '确定售罄吗？';
    }
    $.jBox.confirm(title, "提示", function(v){
        if (v == 'ok'){
        	$.post('/goods/change-main-goods-status',{id:id,use_flg:use_flg},success,'json');
            return false;
            function success(data){
                $.jBox.close();                             //关闭对话框
                if(data.code == 200)
                {
                    $.jBox.tip('处理成功', 'success');
                    window.setTimeout(function () { table_list_reload(); }, 1000);
                }
                else{
                    $.jBox.error(data.val, '错误');
                }
            }
        }else{
            $.jBox.close();
        }
    });
}

$('#table_id_example').on( 'click', '.sorting_1', function () {
    $(this).parent().toggleClass('selected');
    if($(this).parent().hasClass('selected')){
        $(this).find('.publish_class').prop('checked',true);
    }else{
        $(this).find('.publish_class').prop('checked',false);
    }
} );

$('#publish_button').click(function(){
    var publish_array = new Array;
    $('.publish_class').each(function(){
        if($(this).is(':checked')){
            publish_array.push($(this).val());
        }
    });
    if(publish_array == '' || publish_array == null || publish_array == undefined){
        $.jBox.error('请选择要同步的商品', '错误');
        return false;
    }
    $.post('/goods/publish-goods',{id:publish_array},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () { table_list_reload(); }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
})

$('#add_goods_button').click(function(){
    $('#myModalLabel_goods').html('添加商品');
    resetValue();
    $('#add-main-goods-modal').modal('show');
})

$('#add_category_step1').change(function(){
    var add_category_step1 = $('#add_category_step1').val();
    var category_child = category_child_list[add_category_step1];
    var brand = brand_list[add_category_step1];
    $('#add_category_step2').empty();
    $('#add_category_step2').append('<option value="0">选择商品二级分类</option>');
    if(typeof category_child === 'object'){
        for(var i=0;i<category_child.length;i++){
            $('#add_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
        }
    }

    $('#add_brand_id').empty();
    $('#add_brand_id').append('<option value="0">选择商品品牌</option>');
    if(typeof brand === 'object'){
        for(var i=0;i<brand.length;i++){
            $('#add_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
        }
    }
})

$('#add_category_step2').change(function(){
    var add_category_step2 = $('#add_category_step2').val();
    var tag = tag_list[add_category_step2];
    $('#add_tag_id').empty();
    $('#add_tag_id').append('<option value="0">选择商品品类</option>');
    if(typeof tag === 'object'){
        for(var i=0;i<tag.length;i++){
            $('#add_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
        }
    }
})

//提交新增商品表单
$('.ajax_post_add_goods').click(function(){
    var add_goods_name_cn = $('#add_goods_name_cn').val();
    var add_category_step1 = $('#add_category_step1').val();
    var add_category_step2 = $('#add_category_step2').val();
    var add_tag_id = $('#add_tag_id').val();
    var add_brand_id = $('#add_brand_id').val();
    var txt_cn = $('#add_brief_cn').val();
    var txt_other = $('#add_brief_other').val();
    $('#add_brief_cn').text(txt_cn);
    $('#add_brief_other').text(txt_other);
    var unit = $('#add_unit').val();
    if(add_goods_name_cn == ''){
        $.jBox.error('请输入商品中文名称', '错误');
        return false;
    }
    if(add_category_step1 == 0 || add_category_step1 == ''){
        $.jBox.error('请选择商品一级分类', '错误');
        return false;
    }
    if(add_category_step2 == 0 || add_category_step2 == ''){
        $.jBox.error('请选择商品二级分类', '错误');
        return false;
    }
    if(add_tag_id == 0 || add_tag_id == ''){
        $.jBox.error('请选择商品品类', '错误');
        return false;
    }
    if(add_brand_id == 0 || add_brand_id == ''){
        $.jBox.error('请选择商品品牌', '错误');
        return false;
    }
    if(is_null(unit) == null){
    	$.jBox.error('请选择商品价格单位', '错误');
        return false;
    }
    $.post($('#add_main_goods_form').attr('action'),$('#add_main_goods_form').serialize(),success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#add-main-goods-modal').modal('hide');
                $('#goods_name_cn').val(data.val);
                var table = $('#table_id_example').DataTable();
                table.ajax.reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
})

function updateGoods(id){
    resetValue();
    $('#add_main_id').val(id);
    $.post('/goods/get-main-goods-detail',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            setValue(data.val);
            $('#myModalLabel_goods').html('编辑商品');
            $('#add-main-goods-modal').modal('show');
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function resetValue(){
    $('#add_goods_name_cn').val('');
    $('#add_goods_name_other').val('');
    $('#use_flg').val(1);
    $('#add_category_step1').val(0);
    $('#add_category_step2').val(0);
    $('#add_tag_id').val(0);
    $('#add_brand_id').val(0);
    $('#add_unit').val('CNY');
    $('#add_sort').val('');
    $('#add_main_id').val('');
    $('#add_goods_main_pic').val('');
    $('#add_goods_pic_title').val('');
    $('#add_goods_pic_alt').val('');
    $('#add_main_goods_id').val('');
    $('.show-img-btn-main-pic').hide();
    $('.show-img-btn-main-pic').attr('data-img','');
    $('#add_brief_cn').val('');
    $('#add_brief_other').val('');
    $('#brief_cn').text('');
    $('#brief_other').text('');
    var html='<tr><th>关键字</th><th>操作</th></tr>';
    $('#input_table_keyword').html(html);
}

function setValue(data){
    $('#add_goods_name_cn').val(data['goods_name_cn']);
    $('#add_goods_name_other').val(data['goods_name_other']);
    $('#add_category_step1').val(data['category_step1']);
    $('#use_flg').val(data['use_flg']);
    if(data['category_step1'] != 0 && data['category_step1'] != null && data['category_step1'] != undefined){
        var category_child = category_child_list[data['category_step1']];
        $('#add_category_step2').empty();
        $('#add_category_step2').append('<option value="0">选择商品二级分类</option>');
        if(typeof category_child === 'object'){
            for(var i=0;i<category_child.length;i++){
                    $('#add_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
            }
        }
        $('#add_category_step2').val(data['category_step2']);
    }
    if(data['keyword_name'] != '' && data['keyword_name'] != null && data['keyword_name'] != undefined){
    	var akeyword = [];
    	akeyword = data['keyword_name'].split(',');
        for (i=0;i<akeyword.length ;i++ ){
        	var html = '';
        	var class_len = $('#class_len').val();
            var div_class = 'dropdown-sin-'+class_len;
    		html += '<tr><td>';
        	html += '<div class="'+div_class+'">';
       	 	html += '<select style="display:none" name="keyword[]" placeholder="请选择">';
       	 	if(keyword_data.length > 0){
            	keyword_data.forEach(function(data,index){
            		html += '<option value="'+data.name+'" '+(data.name == akeyword[i] ? 'selected' : '')+'>'+data.name+'</option>';
                });
       	 	}
        	html += '</select>';
        	html += '</div>';
        	html += '</td>';
        	html += '<td><a class="del_input_table_tr" href="javascript:;">删除</a></td> </tr>';
        	class_len++;
            $('#class_len').val(class_len);
            $('#input_table_keyword').append(html);
            $('.'+div_class).dropdown({
              readOnly: true,
              input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
            });
    	}
    }
    if(data['category_step2'] != 0 && data['category_step2'] != null && data['category_step2'] != undefined){
        var tag = tag_list[data['category_step2']];
        $('#add_tag_id').empty();
        $('#add_tag_id').append('<option value="0">选择商品品类</option>');
        if(typeof tag === 'object'){
            for(var i=0;i<tag.length;i++){
                $('#add_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
            }
        }
        $('#add_tag_id').val(data['tag_id']);
    }
    if(data['brand_id'] != 0 && data['brand_id'] != null && data['brand_id'] != undefined){
        var brand = brand_list[data['category_step1']];
        $('#add_brand_id').empty();
        $('#add_brand_id').append('<option value="0">选择商品品牌</option>');
        if(typeof brand === 'object'){
            for(var i=0;i<brand.length;i++){
                $('#add_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
            }
        }
        $('#add_brand_id').val(data['brand_id']);
    }
    $('#add_unit').val(data['unit']);
    $('#add_sort').val(data['sort']);
    $('#add_main_id').val(data['id']);
    $('#add_main_goods_id').val(data['main_goods_id']);
    if(data['goods_main_pic'] != 0 && data['goods_main_pic'] != null && data['goods_main_pic'] != undefined){
        $('#add_goods_main_pic').val(data['goods_main_pic']);
        $('.show-img-btn-main-pic').attr('data-img',data['goods_main_pic']);
        $('.show-img-btn-main-pic').show();
    }
    $('#add_goods_pic_title').val(data['goods_pic_title']);
    $('#add_goods_pic_alt').val(data['goods_pic_alt']);
    $('#add_brief_cn').val(data['brief_cn']);
    $('#add_brief_other').val(data['brief_other']);
}

function getSkuList(id){
    $('#select_goods_id').val(id);
    $('#search_goods_sku').val('');
    var table = $('#goods_id_example').DataTable();
    table.ajax.reload();
    $('#show-sku-modal').modal('show');
}

function removeSpecClass(){
	$('.search_spec').val('');
	$("#add_sku_form").find(".active").children("div").removeClass('hide');
}

function modSku(id){
	removeSpecClass();
	$('input[name="spec_color_pic[]"]').remove();
    $('.spec-class').each(function(){
    	var check_val = $(this).val();
		$(this).prop('checked',false);
        $(this).prop('disabled',false);
        $(this).parent().parent().find('#spec_title_'+check_val).prop('disabled',true);
    	$(this).parent().parent().find('#spec_title_'+check_val).addClass('hide');
    	$(this).parent().parent().find('#spec_title_'+check_val).val('');
    	$(this).parent().parent().find('.upload-color-pic').addClass('hide');
        $(this).parent().parent().find('.show-color-pic').addClass('hide');
    });
    $('input[name="spec_color_pic[]"]').val('');
    $('#add_sku_main_id').val(id);
    $('#old_color_spec_id').val('');
    $('#old_is_color_spec_id').val('');
    $.post('/goods/get-goods-sku',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            var result = data.val;
            var is_checked_spec = result.is_checked_spec;
            var old_color_spec_id = result.old_color_spec_id;
            var old_size_spec_id = result.old_size_spec_id;
            var old_other_spec_id = result.old_other_spec_id;
            if(is_checked_spec != '' && is_checked_spec != null && is_checked_spec != undefined){
            	var remarks = result['remark'];
                $('.spec-class').each(function(){
                    var check_val = $(this).val();
                    var check_num = $.inArray(check_val,is_checked_spec);
                    if(eval(check_num) >= 0){
                        $(this).prop('checked',true);
                        $(this).prop('disabled',true);
                        if(remarks[check_val].spec_type == '1'){
                        	$(this).parent().parent().find('#spec_title_'+check_val).prop('disabled',false);
                            $(this).parent().parent().find('#spec_title_'+check_val).removeClass('hide');
                            $(this).parent().parent().find('#spec_title_'+check_val).val(remarks[check_val].remark);
                            $(this).parent().parent().find('.upload-color-pic').removeClass('hide');
                            if(is_null(remarks[check_val].color_pic) != null){
                            	$(this).parent().parent().find('.show-color-pic').removeClass('hide');
                            	$(this).parent().parent().find('.show-color-pic').attr('data-img',remarks[check_val].color_pic);
                            }else{
                            	$(this).parent().parent().find('.show-color-pic').addClass('hide');
                            }
                            var spec_color_pic = $(this).parent().parent().find('input[name="spec_color_pic[]"]').val();
                            if(spec_color_pic == undefined){
                            	$(this).parent().parent().append('<input name="spec_color_pic[]" value="'+(remarks[check_val].color_pic != null ? remarks[check_val].color_pic : '')+'" type="hidden">');
                            }else{
                            	$(this).parent().parent().find('input[name="spec_color_pic[]"]').val(remarks[check_val].color_pic != null ? remarks[check_val].color_pic : '');
                            }
                        }
                    }else{
                    	$(this).prop('checked',false);
                        $(this).prop('disabled',false);
                        $(this).parent().parent().find('#spec_title_'+check_val).prop('disabled',true);
                    	$(this).parent().parent().find('#spec_title_'+check_val).addClass('hide');
                    	$(this).parent().parent().find('#spec_title_'+check_val).val('');
                    	$(this).parent().parent().find('.upload-color-pic').addClass('hide');
                        $(this).parent().parent().find('.show-color-pic').addClass('hide');
                    }
                })
            }
            if(old_other_spec_id != '' && old_other_spec_id != null && old_other_spec_id != undefined){
                $('#old_other_spec_id').val(old_other_spec_id);
            }
            if(old_color_spec_id != '' && old_color_spec_id != null && old_color_spec_id != undefined){
                $('#old_color_spec_id').val(old_color_spec_id);
            }
            if(old_size_spec_id != '' && old_size_spec_id != null && old_size_spec_id != undefined){
                $('#old_size_spec_id').val(old_size_spec_id);
            }
            $('#add-spec-modal').modal('show');
        }else{
            $.jBox.error(data.val, '错误');
        }
    }
}

$('.ajax_post_add_goods_sku').click(function(){
	$('#add_sku_form').find('.spec-class').prop('disabled',false);
    $.post($('#add_sku_form').attr('action'),$('#add_sku_form').serialize(),success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#add-spec-modal').modal('hide');
                $('#select_goods_id').val(data.val);
                var table = $('#goods_id_example').DataTable();
                table.ajax.reload();
            }, 1000);
        }else{
        	$('.spec-class').each(function(){
        		if($(this).prop('checked') == true){
        			$(this).prop('disabled',true);
        		}
        	});
            $.jBox.error(data.val, '错误');
        }
    }
})

function changeGoodsStatus(id,use_flg){
    var title = '';
    if(use_flg == 1){
        title = '确定上架吗？';
    }else if(title == 0){
        title = '确定下架吗？';
    }else{
        title = '确定售罄吗？';
    }
    $.jBox.confirm(title, "提示", function(v){
        if (v == 'ok'){
            $.post('/goods/change-goods-status',{id:id,use_flg:use_flg},success,'json');
            return false;
            function success(data){
                $.jBox.close();                             //关闭对话框
                if(data.code == 200)
                {
                    $.jBox.tip('处理成功', 'success');
                    window.setTimeout(function () {
                        goods_list_reload();
                    }, 1000);
                }
                else{
                	if(use_flg == 1){
                		$('#goods_id_example').find('span[data-id='+id+']').children('input').prop('checked',false);
                	}else{
                		$('#goods_id_example').find('span[data-id='+id+']').children('input').prop('checked',true);
                	}
                    $.jBox.error(data.val, '错误');
                }
            }
        }else{
        	if(use_flg == 1){
        		$('#goods_id_example').find('span[data-id='+id+']').children('input').prop('checked',false);
        	}else{
        		$('#goods_id_example').find('span[data-id='+id+']').children('input').prop('checked',true);
        	}
            $.jBox.close();
        }
    });
}

function updateGoodsSku(id,where){
    $('#input_table').empty();
    $('#input_table').append('<tr><th>链接</th><th>操作</th></tr>');
    $('input:radio[name="is_main"][value="0"]').prop('checked',true);
    $('#update_goods_id').val(id);
    var spec_val = '',spec_color_val = '',goods_list_id = '';
    if(id == ''){
    	var spec_val = $(where).parents('tr').find('select[name=spec_val]').val();
    	var spec_color_val = $(where).parents('tr').find('select[name=spec_color_val]').val();
    	if(spec_val == '' || spec_color_val == ''){
    		$.jBox.error('请选择商品规格和颜色', '错误');
    		return false;
    	}
    }
    var goods_list_id = $('#select_goods_id').val();
    $('#update-sku-modal').find('input[name=spec_val]').val(spec_val);
	$('#update-sku-modal').find('input[name=spec_color_val]').val(spec_color_val);
	$('#update-sku-modal').find('input[name=goods_list_id]').val(goods_list_id);
	$(where).parents('tbody').find('.active').removeClass('active');
	$(where).parents('tr').addClass('active');
	$('.marking-img').html('<label for="mobile">打标图片</label><br/>');
    $.post('/goods/get-goods-detail',{id:id,goods_list_id:goods_list_id,spec_val:spec_val,spec_color_val:spec_color_val},success,'json');
    return false;
	function success(data){
    	if(data.code == 200)
        {
            var result = data.val;
            $('#update_goods_name_cn').val(result.goods_name_cn);
            var imageBathUrl = $('#imageBathUrl').val();
            if(id > 0){
            	$('#update_sku').val(result.sku);
                $('#update_forsale').val(result.forsale);
                $('#update_market_price').val(result.market_price);
                $('#update_sale_price').val(result.sale_price);
                $('#update_use_flg').val(result.use_flg);
                //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
                //$('#update_series').val(result.series);
                //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
                $('#update_model').val(result.model);
                $('input:radio[name="is_main"][value="'+result.is_main+'"]').prop('checked',true);

                if(result.source_list != '' && result.source_list != null && result.source_list != undefined){
                    var source_list = result.source_list;
                    for(var i=0;i<source_list.length;i++){
                        var html = '<tr data-length="'+source_list[i]['sort']+'"><td>'+
                        '<input class="input_table_img" value="'+source_list[i]['source_url']+'" name="source_url[]" class="form-control" style="width:100%;">'+
                        '<input class="input_table_sort" value="'+source_list[i]['sort']+'" name="source_sort[]" type="hidden">'+
                        '<input class="input_source_type" value="'+source_list[i]['source_type']+'" name="source_type[]" type="hidden"></td>'+
                        '<td><a href="javascript:;" class="up_input_table_tr">上移</a>'+
                        ' <a href="javascript:;" class="down_input_table_tr">下移</a>'+
                        ' <a class="del_input_table_tr" href="javascript:;">删除</a>';
                        if(source_list[i]['source_type'] == 0){
                            html = html + ' <a class="check_upload_img" href="javascript:;">上传图片</a>' +
                                ' <a class="check_show_img" onclick="showMoreImg('+source_list[i]['sort']+')" img-url="'+source_list[i]['source_url']+'" href="javascript:;">查看图片</a></td> </tr>';
                        }else{
                            html = html + ' <a class="check_upload_video" href="javascript:;">上传视频</a>' +
                                ' <a target="_blank" class="check_show_video" href="'+imageBathUrl+source_list[i]['source_url']+'">查看视频</a></td> </tr>';
                        }
                        $('#input_table').append(html);
                    }
                }
                var class_len = $('#class_len').val();
                var div_class = 'dropdown-sin-'+class_len;
                var marking_img_html = '';
                marking_img_html += '<div class="'+div_class+'" style="width: 50%;float:left">';
                marking_img_html += '<select name="marking_img_id" id="marking_img_id">';
                marking_img_html += '<option value="0||0" data-url="">请选择</option>';
                var marking_img_url = '';
                if(mark_img.length > 0){
                	mark_img.forEach(function(e,index){
                		var selected = '';
                		if(parseInt(result.marking_img_id) > 0 && result.marking_img_id == e.id){
                        	selected = 'selected';
                        	marking_img_url = e.img_url;
                        }
                		marking_img_html += '<option value="'+e.id+'||'+e.img_url+'" '+selected+'>'+e.img_name+'</option>';
                	});
                }
                marking_img_html += '</select>';
                marking_img_html += '</div>';
                marking_img_html += '<div style="width: 40%;float:right"><img class="show-img-btn hide" src=""/></div>';
                $('.marking-img').append(marking_img_html);
                if(parseInt(result.marking_img_id) > 0){
                	$('.show-img-btn').removeClass('hide');
            		$('.show-img-btn').attr('src',imageBathUrl+marking_img_url);
                }
                $('.'+div_class).dropdown({
                    readOnly: true,
                    input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
               	});
                class_len++;
                $('#class_len').val(class_len);
            }else{
            	$('#update_sku').val('');
                $('#update_forsale').val(1);
                $('#update_market_price').val('');
                $('#update_sale_price').val('');
                $('#update_use_flg').val(1);
                //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
                //$('#update_series').val('');
                //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
                $('#update_model').val('');
                $('input:radio[name="is_main"][value="0"]').prop('checked',true);
                var html = '<tr><th>链接</th><th>操作</th></tr>';
                $('#input_table').html(html);
                
                var class_len = $('#class_len').val();
                var div_class = 'dropdown-sin-'+class_len;
                var marking_img_html = '';
                marking_img_html += '<div class="'+div_class+'" style="width: 50%;float:left">';
                marking_img_html += '<select name="marking_img_id" id="marking_img_id">';
                marking_img_html += '<option value="0||0" data-url="">请选择</option>';
                var marking_img_url = '';
                if(mark_img.length > 0){
                	mark_img.forEach(function(e,index){
                		marking_img_html += '<option value="'+e.id+'||'+e.img_url+'">'+e.img_name+'</option>';
                	});
                }
                marking_img_html += '</select>';
                marking_img_html += '</div>';
                marking_img_html += '<div style="width: 40%;float:right"><img class="show-img-btn hide" src=""/></div>';
                $('.marking-img').append(marking_img_html);
                $('.'+div_class).dropdown({
                    readOnly: true,
                    input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
               	});
                class_len++;
                $('#class_len').val(class_len);
            }
            $('.dropdown-main').on('click','li',function(){
            	var marking_img_id = $(this).attr('data-value');
            	var marking_arr = marking_img_id.split("||");
            	if(marking_arr[1] == '0'){
            		$('.show-img-btn').addClass('hide');
            	}else{
            		$('.show-img-btn').removeClass('hide');
            		$('.show-img-btn').attr('src',imageBathUrl+marking_arr[1]);
            	}
            });
            if(result['hidden_price'] == '1'){
            	$('#update_sale_price').parent().addClass('hide');
            }else{
            	$('#update_sale_price').parent().removeClass('hide');
            }
            $('#update-sku-modal').modal('show');
        }else{
            $.jBox.error(data.val, '错误');
        }
    }
}

$('table').delegate('.check_upload_img','click',function(){
    var check_img_val = $(this).parent().parent().attr('data-length');
    $('#check_img_val').val(check_img_val);
    $('.upload_file').trigger('click');
})

$('table').delegate('.check_upload_video','click',function(){
    var check_img_val = $(this).parent().parent().attr('data-length');
    $('#check_img_val').val(check_img_val);
    $('.upload_file').trigger('click');
})

$('.upload_file').change(function(){
    if(this.value != ''){
    	$('#upload_img_form').submit();
    }
})

$('#upload_img_form').submit(function(e){
    e.preventDefault();
    $(this).ajaxSubmit({
        success:function(data){
            var result = $.parseJSON(data);
            if(result.code == 500){
                $.jBox.error(result.val, '错误');
            }else{
                var check_img_val = $('#check_img_val').val();
                $('#input_table').find('tr').each(function(){
                    var table_data_length = $(this).attr('data-length');
                    if(eval(table_data_length) == eval(check_img_val)){
                        var source_type = $(this).find('.input_source_type').val();
                        var imageBathUrl = $('#imageBathUrl').val();
                        if(source_type == 0){
                            $(this).find('.input_table_img').val(result.val);
                            $(this).find('a.check_show_img').remove();
                            $(this).find('.check_upload_img').after(' <a class="check_show_img" onclick="showMoreImg('+check_img_val+')" img-url="'+result.val+'" href="javascript:;">查看图片</a>');
                        }else{
                            $(this).find('.input_table_img').val(result.val);
                            $(this).find('a.check_show_img').remove();
                            $(this).find('.check_upload_video').after(' <a target="_blank" class="check_show_video" href="'+imageBathUrl+result.val+'">查看视频</a>');
                        }
                    }
                });
                $('#upload_img_form').find('input[type=file]').closest('form').get(0).reset();
            }
        }
    });

});

//查看图片
function showMoreImg(check_img_val){
    var img_url = '';
    $('#input_table').find('tr').each(function(){
        var table_data_length = $(this).attr('data-length');
        if(eval(table_data_length) == eval(check_img_val)){
            img_url = $(this).find('.check_show_img').attr('img-url');
        }
    })
    var json = {
        "title": "分类图片", //相册标题
        "id": 0, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "",//图片名
                "pid": 0, //图片id
                "src": $('#imageBathUrl').val() + img_url, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
    });
}

//查看图片
function showMoreImg2(where){
    var img_url = where.attr('img-url');
    var json = {
        "title": "分类图片", //相册标题
        "id": 0, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "",//图片名
                "pid": 0, //图片id
                "src": $('#imageBathUrl').val() + img_url, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
    });
}

//添加图片视频
$('#add_input').click(function(){
    var tr_length = $('#input_table').find('tr').length;

    var tr_length_ot = 0;

    $('#input_table').find('tr').each(function(){
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length != undefined){
            tr_length_ot = eval(data_length);
        }
    })

    if(eval(tr_length_ot) > 0){
        tr_length = tr_length_ot + 1;
    }

    var is_source_type = $('input:radio[name="is_source_type"]:checked').val();
    var html = '<tr data-length="'+tr_length+'"><td>'+
        '<input class="input_table_img" value="" name="source_url[]" class="form-control" style="width:100%;">'+
        '<input class="input_table_sort" value="'+tr_length+'" name="source_sort[]" type="hidden">'+
        '<input class="input_source_type" value="'+is_source_type+'" name="source_type[]" type="hidden"></td>'+
        '<td><a href="javascript:;" class="up_input_table_tr">上移</a>'+
        ' <a href="javascript:;" class="down_input_table_tr">下移</a>'+
        ' <a class="del_input_table_tr" href="javascript:;">删除</a>';
    if(is_source_type == 0){
        var html = html + ' <a class="check_upload_img" href="javascript:;">上传图片</a></td> </tr>';
    }else{
        var html = html + ' <a class="check_upload_video" href="javascript:;">上传视频</a></td> </tr>';
    }

    $('#input_table').append(html);
})

//添加关键字
$('#add_input_keyword').click(function(){
    var tr_length = $('#input_table_keyword').find('tr').length;

    var tr_length_ot = 0;

    $('#input_table').find('tr').each(function(){
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length != undefined){
            tr_length_ot = eval(data_length);
        }
    })

    if(eval(tr_length_ot) > 0){
        tr_length = tr_length_ot + 1;
    }
    var class_len = $('#class_len').val();
    var div_class = 'dropdown-sin-'+class_len;
    var html = '<tr><td>';
    	html += '<div class="'+div_class+'">';
   	 	html += '<select style="display:none" name="keyword[]" placeholder="请选择">';
   	 	if(keyword_data.length > 0){
       	 	keyword_data.forEach(function(data,index){
        		html += '<option value="'+data.name+'">'+data.name+'</option>';
            });
       	}
    	html += '</select>';
    	html += '</div>';
    	html += '</td>';
    	html += '<td><a class="del_input_table_tr" href="javascript:;">删除</a></td> </tr>';

    $('#input_table_keyword').append(html);

    $('.'+div_class).dropdown({
      readOnly: true,
      input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
    });
    class_len++;
    $('#class_len').val(class_len);
})

$('table').delegate('.del_input_table_tr','click',function(){
    $(this).parent().parent().remove();
})

$('table').delegate('.up_input_table_tr','click',function(){
    var tr_index = $(this).parent().parent().prev().index();
    if(eval(tr_index) == 0){
        return true;
    }else{
        var obj = $(this).parent().parent().clone();
        $(this).parent().parent().prev().before(obj);
        $(this).parent().parent().remove();
    }

    $('#input_table').find('tr').each(function(){
        var tr_index = $(this).index();
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length!= undefined && data_length != 0){
            $(this).attr('data-length',tr_index);
            $(this).find('.input_table_sort').val(tr_index);
        }
    })
})

$('table').delegate('.down_input_table_tr','click',function(){
    var tr_index = $(this).parent().parent().next().index();
    if(eval(tr_index) > eval(-1)){
        var obj = $(this).parent().parent().clone();
        $(this).parent().parent().next().after(obj);
        $(this).parent().parent().remove();
    }

    $('#input_table').find('tr').each(function(){
        var tr_index = $(this).index();
        var data_length = $(this).attr('data-length');
        if(data_length != '' && data_length!= undefined && data_length != 0){
            $(this).attr('data-length',tr_index);
            $(this).find('.input_table_sort').val(tr_index);
        }
    })
})

$('.ajax_post_update_goods_sku').click(function(){
    var update_sku = $('#update_sku').val();
    var update_market_price = $('#update_market_price').val();
    var update_sale_price = $('#update_sale_price').val();

    if(update_sku == ''){
        $.jBox.error('请输入物料号', '错误');
        return false;
    }

    if(update_market_price == ''){
        $.jBox.error('请输入市场价', '错误');
        return false;
    }
    
    var has_hide = $('#update_sale_price').parent().hasClass('hide');
    if(has_hide == false){
    	if(update_sale_price == '' || update_sale_price == '0.00'){
            $.jBox.error('请输入销售价', '错误');
            return false;
        }
    }

    $.post($('#update_sku_form').attr('action'),$('#update_sku_form').serialize(),success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            $('#update-sku-modal').modal('hide');
            var res = data.val;
            if(res.is_add == true){
            	var active = $('#goods_id_example').find('.active');
            	active.children('td').eq(0).html('<a href="javascript:" onclick="updateGoodsSku('+res.id+',this)">修改</a> | <a href="javascript:" class="text-danger" onclick="examineGoodsSku('+res.id+')">审核</a>');
            	active.children('td').eq(1).html(res.id);
            	active.children('td').eq(2).html(res.goods_name_cn);
            	active.children('td').eq(3).html(res.goods_id);
            	active.children('td').eq(4).html(res.sku);
            	active.children('td').eq(5).html(res.spec_val);
            	active.children('td').eq(6).html(res.spec_color_val);
            	active.children('td').eq(7).html(1);
            	var status = '上架';
            	if(res.use_flg == 0){
            		status = '下架';
            	}
            	active.children('td').eq(8).html(status);
            	var status_sxj = '下架';
            	if(res.use_flg == 0){
            		status_sxj = '上架';
            	}
//            	active.children('td').eq(9).html('<a href="javascript:" onclick="changeGoodsStatus('+res.id+','+(res.use_flg == 1 ? 0 : 1)+')">'+status_sxj+'</a>');
            	active.children('td').eq(9).html('<span class="switch" data-id="res.id" data-flg="0"><input  style="width:20px;height:20px;" type="checkbox" checked="" class="input-check"></span>');
            	active.children('td').eq(10).html('<span class="text-danger">待审核</span>');
            	active.children('td').eq(11).html('--');
            }else{
            	window.setTimeout(function () {
            		goods_list_reload();
            		table_list_reload();
                }, 1000);
            }
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
})

$('.upload-color-pic').click(function(){
	var spec_id = $(this).prev().attr('id');
	$('#spec_id').val(spec_id);
    $('.upload_color_pic').trigger('click');
});

$('.upload_color_pic').change(function(){
    if(this.value == ''){

    }else{
        $('#upload_spec_color_pic').submit();
    }
});

$('#upload_spec_color_pic').submit(function(e){
    e.preventDefault();
    $(this).ajaxSubmit({
        success:function(data){
            var result = $.parseJSON(data);
            if(result.code == 500){
                $.jBox.error(result.val, '错误');
            }else{
            	var spec_id = $('#spec_id').val();
            	$('#'+spec_id).parent().find('.show-color-pic').attr('data-img',result.val);
            	$('#'+spec_id).parent().find('.show-color-pic').removeClass('hide');
            	var spec_color_pic = $('#'+spec_id).parent().find('input[name="spec_color_pic[]"]').val();
            	if(spec_color_pic == undefined){
            		$('#'+spec_id).parent().append('<input name="spec_color_pic[]" value="'+result.val+'" type="hidden">');
            	}else{
            		$('#'+spec_id).parent().find('input[name="spec_color_pic[]"]').val(result.val);	
            	}
                $('#upload_spec_color_pic').find('input[type=file]').closest('form').get(0).reset();
            }
        }
    });

});

$('.upload-img-btn-main-pic').click(function(){
    $('.upload_file_goods_main_pic').trigger('click');
});

$('.upload_file_goods_main_pic').change(function(){
    if(this.value == ''){

    }else{
        $('#upload_goods_main_pic').submit();
    }
});

$('#goods_id_example').on('click','.del-line',function(){
	$(this).parents('tr').addClass('hide');
});

$('#add_goods_sku_button').on('click',function(){
	if($('#goods_id_example').find('.hide').length > 0){
		$('#goods_id_example').find('.hide').each(function(e){
			if(e == 0){
				$(this).removeClass('hide');
			}
		});
	}else{
		var select_goods_id = $('#select_goods_id').val();
		var added_sku = [];
		$('input[name="added_sku[]"]').each(function(){
			added_sku.push($(this).val());
		});
		$.post('/goods/get-spec-data',{select_goods_id:select_goods_id,added_sku:added_sku},success,'json');
		return false;
		function success(data){
			if(data.code == 200){
				var goods_spec = data.val;
				var tr_count = $('#goods_id_example').find('tbody').children('tr').size();
				var can_add_spec = new Array();
				can_add_spec = goods_spec.can_add_spec.split('-');
				if(eval(tr_count) < eval(goods_spec.can_add_count)){
					var html = '<tr role="row" class="odd">';
					html += '<td><a href="javascript:" onclick="updateGoodsSku(\'\',this)">修改</a><input name="added_sku[]" type="hidden" value="'+goods_spec.can_add_spec+'"/></td>';
					html += '<td></td><td></td><td></td><td></td>';
					html += '<td>';
	        		html += '<select class="form-control" name="spec_val">';
	        		goods_spec[2].forEach(function(e,index){
	        			html += '<option '+($.inArray(e.spec_id,can_add_spec) >= 0 ? 'selected' : '')+' value="'+e.spec_id+'">'+e.spec_val+'</option>';
	        		});
	                html += '</select>';
					html += '</td>';
					html += '<td>';
					html += '<select class="form-control" name="spec_color_val">';
	        		goods_spec[1].forEach(function(e,index){
	        			html += '<option '+($.inArray(e.spec_id,can_add_spec) >= 0 ? 'selected' : '')+' value="'+e.spec_id+'">'+e.spec_val+'</option>';
	        		});
	                html += '</select>';
					html += '</td>';
					html += '<td>--</td><td>--</td><td>--</td><td>--</td>';
					html += '<td><span><a href="javascript:void(0);" class="text-danger del-line">删除</a></span></td>';
					html += '</tr>';
					$('#goods_id_example').find('tbody').append(html);
				}else{
					$.jBox.error('已达到规格组合的最大量', '错误');
				}
	        }else{
	        	$.jBox.error(data.val, '错误');
	        }
		}
	}
});

$('#upload_goods_main_pic').submit(function(e){
    e.preventDefault();
    $(this).ajaxSubmit({
        success:function(data){
            var result = $.parseJSON(data);
            if(result.code == 500){
                $.jBox.error(result.val, '错误');
            }else{
                $('#add_goods_main_pic').val(result.val);
                $('.show-img-btn-main-pic').attr('data-img',result.val);
                $('.show-img-btn-main-pic').show();
                
                $('#upload_goods_main_pic').find('input[type=file]').closest('form').get(0).reset();
            }
        }
    });

});

$('.show-img-btn-main-pic,.show-img-btn-examine-pic,.show-img-btn-examine-pic_2, .show-color-pic').click(function(){
    var img_url = $(this).attr('data-img');
    showImg(img_url);
})

function showImg(objKey){
    if(objKey == '' || objKey == null || objKey == undefined){
        $.jBox.error('数据为空', '错误');
        return false;
    }
    var json = {
        "title": "分类图片", //相册标题
        "id": 0, //相册id
        "start": 0, //初始显示的图片序号，默认0
        "data": [   //相册包含的图片，数组格式
            {
                "alt": "",//图片名
                "pid": 0, //图片id
                "src": $('#imageBathUrl').val() + objKey, //原图地址
                "thumb": "" //缩略图地址
            }
        ]
    };
    layer.photos({
        photos: json
    });
}

$("#add_brief_cn , #add_brief_other").xheditor({
	upImgUrl: '/common/xhedit-upload',
	upImgExt: "jpg,jpeg,gif,bmp,png",
	onUpload:insertUpload
},true);

function insertUpload(arrMsg)
{
	var i,msg;
	for(i=0;i<arrMsg.length;i++)
	{
		msg=arrMsg[i];
		$("#xheImgUrl").html(msg);
	}
}

function goodsExamine(id){
	resetExamineValue();
    $.post('/goods/get-examine-goods-detail',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            setExamineValue(data.val);
            $('#examine-goods').modal('show');
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function examineGoodsSku(id){
	resetExamineGoodsValue();
    $.post('/goods/get-examine-goods-sku-detail',{id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            setExamineGoodsValue(data.val);
            $('#examine-goods-sku').modal('show');
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function resetExamineValue(){
    $('#examine_goods_name_cn').val('');
    $('#examine_goods_name_other').val('');
    $('#examine_category_step1').val(0);
    $('#examine_category_step2').val(0);
    $('#examine_tag_id').val(0);
    $('#examine_brand_id').val(0);
    //mod by lizenan 20180119 【后台需求】关键词维护改进   430  start
    $('#examine_series').val('');
    $('.show-img-btn-examine-pic').hide();
    $('#examine_goods_pic_title').val('');
    $('#examine_goods_pic_alt').val('');
    var html='<tr><th>关键字</th></tr>';
    $('#examine_input_table_keyword').html(html);
    $('#examine_navigation_identification').html('');
    $('#examine_unit').val('CNY');
    $('#examine_sort').val('');
    $('#examine_hidden_price').val('');
    //add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  start
    $('#examine_see_more_product').val('');
    $('#examine_brief_cn').val('');
    $('#examine_brief_other').val('');
    $('#examine_use_flg').val('');
//    $('#examine_goods_identification').val('');

    $('#examine_goods_name_cn_2').val('');
    $('#examine_goods_name_other_2').val('');
    $('#examine_category_step1_2').val(0);
    $('#examine_category_step2_2').val(0);
    $('#examine_tag_id_2').val(0);
    $('#examine_brand_id_2').val(0);
    $('#examine_series_2').val('');
    //mod by lizenan 20180119 【后台需求】关键词维护改进   430  end
    $('#examine_goods_pic_title_2').val('');
    $('#examine_goods_pic_alt_2').val('');
    var html='<tr><th>关键字</th></tr>';
    $('#examine_input_table_keyword_2').html(html);
    $('#examine_navigation_identification_2').html('');
    $('#examine_unit_2').val('CNY');
    $('#examine_sort_2').val('');
    $('#examine_hidden_price_2').val('');
    //add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  start
    $('#examine_see_more_product_2').val('');
    $('#examine_brief_cn_2').val('');
    $('#examine_brief_other_2').val('');
    $('#examine_use_flg_2').val('');
//    $('#examine_goods_identification_2').val('');

    $('#examine_goods_name_cn_2').parent().css('visibility','hidden');
    $('#examine_goods_name_other_2').parent().css('visibility','hidden');
    $('#examine_category_step1_2').css('visibility','hidden');
    $('#examine_category_step2_2').css('visibility','hidden');
    $('#examine_category_step1_2').parent().css('visibility','hidden');
    $('#examine_tag_id_2').parent().css('visibility','hidden');
    $('#examine_brand_id_2').parent().css('visibility','hidden');
    $('#examine_series_2').parent().css('visibility','hidden');
    $('.show-img-btn-examine-pic_2').parent().css('visibility','hidden');
    $('#examine_goods_pic_title_2').parent().css('visibility','hidden');
    $('#examine_goods_pic_alt_2').parent().css('visibility','hidden');
    $('#examine_input_table_keyword_2').parent().css('visibility','hidden');
    $('#examine_navigation_identification_2').parent().css('visibility','hidden');
    $('#examine_unit_2').parent().css('visibility','hidden');
    $('#examine_sort_2').parent().css('visibility','hidden');
    $('#examine_hidden_price_2').parent().css('visibility','hidden');
    $('#examine_see_more_product_2').parent().css('visibility','hidden');
    $('#examine_brief_cn_2').parent().css('visibility','hidden');
    $('#examine_brief_other_2').parent().css('visibility','hidden');
    $('#examine_use_flg_2').parent().css('visibility','hidden');
//    $('#examine_goods_identification_2').parent().css('visibility','hidden');
}

function setExamineValue(data){
	var new_data = data.new_data;
	var old_data = data.old_data;
    $('#examine_goods_name_cn').val(new_data['goods_name_cn']);
    $('#examine_goods_name_other').val(new_data['goods_name_other']);
    $('#examine_category_step1').val(new_data['category_step1']);
    $('#examine_use_flg').val(new_data['use_flg']);
    $('#examine_hidden_price').val(new_data['hidden_price']);
    //add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  start
    $('#examine_see_more_product').prop('checked',new_data['see_more_product'] == '1' ? true : false);
//    $('#examine_goods_identification').val(new_data['identification_id']);
    //mod by lizenan 20180119 【后台需求】关键词维护改进   430  start
    $('#examine_series').val(new_data['series']);
    if(new_data['category_step2'] != 0 && new_data['category_step2'] != null && new_data['category_step2'] != undefined){
        var category_child = category_child_list[new_data['category_step1']];
        $('#examine_category_step2').empty();
        $('#examine_category_step2').append('<option value="0">选择商品二级分类</option>');
        if(typeof category_child === 'object'){
            for(var i=0;i<category_child.length;i++){
				$('#examine_category_step2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
            }
        }
        $('#examine_category_step2').val(new_data['category_step2']);
    }
    if(new_data['tag_id'] != 0 && new_data['tag_id'] != null && new_data['tag_id'] != undefined){
        var tag = tag_list[new_data['category_step2']];
        $('#examine_tag_id').empty();
        $('#examine_tag_id').append('<option value="0">选择商品品类</option>');
        if(typeof tag === 'object'){
            for(var i=0;i<tag.length;i++){
                $('#examine_tag_id').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
            }
        }
        $('#examine_tag_id').val(new_data['tag_id']);
    }
    if(new_data['brand_id'] != 0 && new_data['brand_id'] != null && new_data['brand_id'] != undefined){
        var brand = brand_list[new_data['category_step1']];
        $('#examine_brand_id').empty();
        $('#examine_brand_id').append('<option value="0">选择商品品牌</option>');
        if(typeof brand === 'object'){
            for(var i=0;i<brand.length;i++){
                $('#examine_brand_id').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
            }
        }
        $('#examine_brand_id').val(new_data['brand_id']);
    }
    if(new_data['goods_main_pic'] != 0 && new_data['goods_main_pic'] != null && new_data['goods_main_pic'] != undefined){
        $('.show-img-btn-examine-pic').attr('data-img',new_data['goods_main_pic']);
        $('.show-img-btn-examine-pic').show();
    }
    $('#examine_goods_pic_title').val(new_data['goods_pic_title']);
    $('#examine_goods_pic_alt').val(new_data['goods_pic_alt']);
    var akeyword = [];
    var akeyword_old = [];
    if(old_data && old_data != '' && old_data != null){
    	if(old_data['keyword_name']){
        	akeyword_old = old_data['keyword_name'].split(',');
        }
    }
	if(new_data['keyword_name'] != '' && new_data['keyword_name'] != null && new_data['keyword_name'] != undefined){
    	akeyword = new_data['keyword_name'].split(',');
        for (i=0;i<akeyword.length ;i++ ){
        	var html = '';
        	var class_len = $('#class_len').val();
            var div_class = 'dropdown-sin-'+class_len;
    		html += '<tr><td>';
//        	html += '<div class="'+div_class+'">';
//       	 	html += '<select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择">';
//       	 	if(keyword_data.length > 0){
//            	keyword_data.forEach(function(data,index){
//            		html += '<option value="'+data.name+'" '+(data.name == akeyword[i] ? 'selected' : '')+'>'+data.name+'</option>';
//                });
//       	 	}
//        	html += '</select>';
//        	html += '</div>';
    		html += '<input style="width: 50%;" disabled="" value="'+akeyword[i]+'" class="form-control" name="keyword[]" type="text">';
        	html += '</td></tr>';
        	class_len++;
            $('#class_len').val(class_len);
            $('#examine_input_table_keyword').append(html);
    	}
        if(akeyword_old.length > akeyword.length){
    		for (i=0;i<akeyword_old.length-akeyword.length;i++ ){
        		var html = '';
        		html += '<tr style="visibility: hidden;"><td><input style="width: 50%;" disabled="" value="" class="form-control" name="keyword[]" type="text"></td></tr>';
        		//html = '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>';
        		$('#examine_input_table_keyword').append(html);
        	}
       	}
    }else{
    	var html = '';
    	for (i=0;i<akeyword_old.length ;i++ ){
    		html += '<tr style="visibility: hidden;"><td><input style="width: 50%;" disabled="" value="" class="form-control" name="keyword[]" type="text"></td></tr>';
    		//html += '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
    	}
    	$('#examine_input_table_keyword').append(html);
    }
	/*商品导航标识*/
	var new_nav = new_data['goods_nav'];
    var nav_identification_html = '';
    if(nav_identification_list.length > 0){
    	nav_identification_list.forEach(function(e){
        	var son = e.son ? e.son : [];
        	nav_identification_html += '<div class="col-md-12">';
        	nav_identification_html += '<div style="float:left;width:100px">';
        	nav_identification_html += '<input style="width:18px;height:18px;" disabled '+($.inArray(e.id,new_nav) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="radio" value="'+e.id+'">'+e.name;
        	nav_identification_html += '</div>';
			if(son.length > 0){
				nav_identification_html += '<div class="second_level">';
				son.forEach(function(i){
					nav_identification_html += '<div style="float:left;width:120px;">';
					nav_identification_html += '<input style="width:18px;height:18px;" disabled '+($.inArray(i.id,new_nav) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="checkbox" value="'+i.id+'"> '+i.name;
					nav_identification_html += '</div>';
				});
				nav_identification_html += '</div>';
			}
			nav_identification_html += '</div>';
       	});
    }
    $('#examine_navigation_identification').html(nav_identification_html);
    $('#examine_unit').val(new_data['unit']);
    $('#examine_sort').val(new_data['sort']);
    $('#examine_brief_cn').val(new_data['brief_cn']);
    $('#examine_brief_other').val(new_data['brief_other']);
    //原始数据
    if(old_data && old_data != '' && old_data != null){
    	if(is_null(old_data['goods_name_cn']) != is_null(new_data['goods_name_cn'])){
        	$('#examine_goods_name_cn_2').val(old_data['goods_name_cn']);
        	$('#examine_goods_name_cn_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_name_cn_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['series']) != is_null(new_data['series'])){
        	$('#examine_series_2').val(old_data['series']);
        	$('#examine_series_2').parent().removeAttr('style');
       	}else{
       		$('#examine_series_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['goods_name_other']) != is_null(new_data['goods_name_other'])){
        	$('#examine_goods_name_other_2').val(old_data['goods_name_other']);
        	$('#examine_goods_name_other_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_name_other_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['use_flg']) != is_null(new_data['use_flg'])){
    		$('#examine_use_flg_2').val(old_data['use_flg']);
        	$('#examine_use_flg_2').parent().removeAttr('style');
    	}else{
    		$('#examine_use_flg_2').parent().css('visibility','hidden');
    	}
    	if(is_null(old_data['hidden_price']) != is_null(new_data['hidden_price'])){
//    		$('#examine_hidden_price_2').prop('checked',old_data['hidden_price'] == '1' ? true : false);
    		$('#examine_hidden_price_2').val(old_data['hidden_price']);
        	$('#examine_hidden_price_2').parent().removeAttr('style');
    	}else{
    		$('#examine_hidden_price_2').parent().css('visibility','hidden');
    	}
    	//add by lizenan 20180129 【商城需求】商品详情页增加查看同品牌商品的按钮   488  start
    	if(is_null(old_data['see_more_product']) != is_null(new_data['see_more_product'])){
    		$('#examine_see_more_product_2').prop('checked',old_data['see_more_product'] == '1' ? true : false);
        	$('#examine_see_more_product_2').parent().removeAttr('style');
    	}else{
    		$('#examine_see_more_product_2').parent().css('visibility','hidden');
    	}
//    	if(is_null(old_data['identification_id']) != is_null(new_data['identification_id'])){
//    		$('#examine_goods_identification_2').val(old_data['identification_id']);
//        	$('#examine_goods_identification_2').parent().removeAttr('style');
//    	}else{
//    		$('#examine_goods_identification_2').parent().css('visibility','hidden');
//    	}
    	if(is_null(old_data['category_step1']) != is_null(new_data['category_step1'])){
        	$('#examine_category_step1_2').val(old_data['category_step1']);
        	$('#examine_category_step1_2').parent().removeAttr('style');
        	$('#examine_category_step1_2').removeAttr('style');
       	}else{
       		$('#examine_category_step1_2').css('visibility','hidden');
       		$('#examine_category_step1_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['category_step2']) != is_null(new_data['category_step2'])){
        	$('#examine_category_step2_2').removeAttr('style');
        	var category_child = category_child_list[old_data['category_step1']];
            $('#examine_category_step2_2').empty();
            $('#examine_category_step2_2').append('<option value="0">选择商品二级分类</option>');
            if(typeof category_child === 'object'){
                for(var i=0;i<category_child.length;i++){
    				$('#examine_category_step2_2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
                }
            }
            $('#examine_category_step2_2').val(old_data['category_step2']);
       	}else{
       		$('#examine_category_step2_2').css('visibility','hidden');
       	}
       	if(is_null(old_data['category_step1']) == is_null(new_data['category_step1']) && is_null(old_data['category_step2']) == is_null(new_data['category_step2'])){
           	$('#examine_category_step1_2').parent().css('visibility','hidden');
           	$('#examine_category_step1_2').css('visibility','hidden');
           	$('#examine_category_step2_2').css('visibility','hidden');
        }else{
        	$('#examine_category_step1_2').val(old_data['category_step1']);
       		$('#examine_category_step2_2').val(old_data['category_step2']);
        	$('#examine_category_step1_2').parent().removeAttr('style');
        	$('#examine_category_step1_2').removeAttr('style');
        	$('#examine_category_step2_2').removeAttr('style');
        	$('#examine_category_step1_2').css('width','50%');
        	$('#examine_category_step2_2').css({'width':'50%','margin-top':'10px'});
        	
        	var category_child = category_child_list[old_data['category_step1']];
            $('#examine_category_step2_2').empty();
            $('#examine_category_step2_2').append('<option value="0">选择商品二级分类</option>');
            if(typeof category_child === 'object'){
                for(var i=0;i<category_child.length;i++){
    				$('#examine_category_step2_2').append('<option value="'+category_child[i]['id']+'">'+category_child[i]['category_name']+'</option>');
                }
            }
            $('#examine_category_step2_2').val(old_data['category_step2']);
        	
       	}
       	if(is_null(old_data['tag_id']) != is_null(new_data['tag_id'])){
	       	 var tag = tag_list[old_data['category_step2']];
	         $('#examine_tag_id_2').empty();
	         $('#examine_tag_id_2').append('<option value="0">选择商品品类</option>');
	         if(typeof tag === 'object'){
	             for(var i=0;i<tag.length;i++){
	                 $('#examine_tag_id_2').append('<option value="'+tag[i]['tag_id']+'">'+tag[i]['tag_name']+'</option>');
	             }
	         }
        	$('#examine_tag_id_2').val(old_data['tag_id']);
        	$('#examine_tag_id_2').parent().removeAttr('style');
       	}else{
       		$('#examine_tag_id_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['brand_id']) != is_null(new_data['brand_id'])){
       		var brand = brand_list[old_data['category_step1']];
            $('#examine_brand_id_2').empty();
            $('#examine_brand_id_2').append('<option value="0">选择商品品牌</option>');
            if(typeof brand === 'object'){
                for(var i=0;i<brand.length;i++){
                    $('#examine_brand_id_2').append('<option value="'+brand[i]['brand_id']+'">'+brand[i]['brand_name']+'</option>');
                }
            }
        	$('#examine_brand_id_2').val(old_data['brand_id']);
        	$('#examine_brand_id_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brand_id_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['goods_main_pic']) != is_null(new_data['goods_main_pic'])){
       		$('.show-img-btn-examine-pic_2').attr('data-img',old_data['goods_main_pic']);
       		$('.show-img-btn-examine-pic_2').parent().removeAttr('style');
       	}else{
       		$('.show-img-btn-examine-pic_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['goods_pic_title']) != is_null(new_data['goods_pic_title'])){
       		$('#examine_goods_pic_title_2').val(old_data['goods_pic_title']);
       		$('#examine_goods_pic_title_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_pic_title_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['goods_pic_alt']) != is_null(new_data['goods_pic_alt'])){
       		$('#examine_goods_pic_alt_2').val(old_data['goods_pic_alt']);
       		$('#examine_goods_pic_alt_2').parent().removeAttr('style');
       	}else{
       		$('#examine_goods_pic_alt_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['keyword_name']) != is_null(new_data['keyword_name'])){
           	if(old_data['keyword_name']){
                for (i=0;i<akeyword_old.length ;i++ ){
                	var html = '';
                	var class_len = $('#class_len').val();
                    var div_class = 'dropdown-sin-'+class_len;
            		html += '<tr><td>';
//                	html += '<div class="'+div_class+'">';
//               	 	html += '<select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择">';
//               	 	if(keyword_data.length > 0){
//                    	keyword_data.forEach(function(data,index){
//                    		html += '<option value="'+data.name+'" '+(data.name == akeyword_old[i] ? 'selected' : '')+'>'+data.name+'</option>';
//                        });
//               	 	}
//                	html += '</select>';
//                	html += '</div>';
            		html += '<input style="width: 50%;" disabled="" value="'+akeyword_old[i]+'" class="form-control" name="keyword[]" type="text">';
                	html += '</td></tr>';
                	class_len++;
                    $('#class_len').val(class_len);
                    $('#examine_input_table_keyword_2').append(html);
            	}
            	if(akeyword.length > akeyword_old.length){
            		for (i=0;i<akeyword.length-akeyword_old.length;i++){
                		var html = '';
                		html += '<tr style="visibility: hidden;"><td><input style="width: 50%;" disabled="" value="" class="form-control" name="keyword[]" type="text"></td></tr>';
                		//html = '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
                		$('#examine_input_table_keyword_2').append(html);
                	}
               	}
            }else{
                var html = '';
            	for (i=0;i<akeyword.length ;i++ ){
            		html += '<tr style="visibility: hidden;"><td><input style="width: 50%;" disabled="" value="" class="form-control" name="keyword[]" type="text"></td></tr>';
            		//html += '<tr style="visibility: hidden;"><td><div><select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择"></select><div/></td></tr>'
            	}
            	$('#examine_input_table_keyword_2').append(html);
            }
            $('#examine_input_table_keyword_2').parent().removeAttr('style');
       	}else{
       		if(old_data['keyword_name']){
       			for (i=0;i<akeyword_old.length ;i++ ){
                	var html = '';
            		html += '<tr><td>';
//                	html += '<div class="'+div_class+'">';
//               	 	html += '<select disabled name="keyword[]" style="width:50%" class="form-control" placeholder="请选择">';
//               	 	if(keyword_data.length > 0){
//                    	keyword_data.forEach(function(data,index){
//                    		html += '<option value="'+data.name+'" '+(data.name == akeyword_old[i] ? 'selected' : '')+'>'+data.name+'</option>';
//                        });
//               	 	}
//                	html += '</select>';
//                	html += '</div>';
            		html += '<input style="width: 50%;" disabled="" value="" class="form-control" name="keyword[]" type="text">';
                	html += '</td></tr>';
                    $('#examine_input_table_keyword_2').append(html);
            	}
       			$('#examine_input_table_keyword_2').parent().css('visibility','hidden');
       		}
       		$('#examine_input_table_keyword_2').parent().css('visibility','hidden');
       	}
       	/*原商品导航标识*/
    	var old_nav = old_data['goods_nav'];
    	if(old_nav != new_nav){
    		var nav_identification_html = '';
            if(nav_identification_list.length > 0){
            	nav_identification_list.forEach(function(e){
                	var son = e.son ? e.son : [];
                	nav_identification_html += '<div class="col-md-12">';
                	nav_identification_html += '<div style="float:left;width:100px">';
                	nav_identification_html += '<input style="width:18px;height:18px;" disabled '+($.inArray(e.id,old_nav) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="radio" value="'+e.id+'">'+e.name;
                	nav_identification_html += '</div>';
        			if(son.length > 0){
        				nav_identification_html += '<div class="second_level">';
        				son.forEach(function(i){
        					nav_identification_html += '<div style="float:left;width:120px;">';
        					nav_identification_html += '<input style="width:18px;height:18px;" disabled '+($.inArray(i.id,old_nav) >= 0 ? 'checked' : '')+' name="navigation_identification_id" type="checkbox" value="'+i.id+'"> '+i.name;
        					nav_identification_html += '</div>';
        				});
        				nav_identification_html += '</div>';
        			}
        			nav_identification_html += '</div>';
               	});
            }
            $('#examine_navigation_identification_2').parent().removeAttr('style');
            $('#examine_navigation_identification_2').html(nav_identification_html);
    	}else{
    		$('#examine_navigation_identification_2').parent().css('visibility','hidden');
    	}
       	if(is_null(old_data['unit']) != is_null(new_data['unit'])){
       		$('#examine_unit_2').val(old_data['unit']);
       		$('#examine_unit_2').parent().removeAttr('style');
       	}else{
       		$('#examine_unit_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['sort']) != is_null(new_data['sort'])){
       		$('#examine_sort_2').val(old_data['sort']);
       		$('#examine_sort_2').parent().removeAttr('style');
       	}else{
       		$('#examine_sort_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['brief_cn']) != is_null(new_data['brief_cn'])){
       		$('#examine_brief_cn_2').val(old_data['brief_cn']);
       		$('#examine_brief_cn_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brief_cn_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['brief_other']) != is_null(new_data['brief_other'])){
       		$('#examine_brief_other_2').val(old_data['brief_other']);
       		$('#examine_brief_other_2').parent().removeAttr('style');
       	}else{
       		$('#examine_brief_other_2').parent().css('visibility','hidden');
       	}
    }
    //mod by lizenan 20180119 【后台需求】关键词维护改进   430  start
    $('#goods_list_edit_id').val(new_data['id']);
}

function resetExamineGoodsValue(){
    $('#sale_goods_name').val('');
    $('#examine-goods-sku').find('input[name=sale_product]').prop('checked',false);
    $('#sale_sku').val('');
    $('#sale_forsale').val(0);
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
    //$('#sale_series').val('');
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
    $('#sale_model').val('');
    $('.marking-img-1').html('<label for="mobile">打标图片</label><br/>');
    $('#sale_market_price').val('');
    $('#sale_price').val('');
    $('#sale_use_flg').val(1);
    $('#sale_source').html('');

    $('#sale_goods_name_2').val('');
    $('#examine-goods-sku').find('input[name=sale_product_2]').prop('checked',false);
    $('#sale_sku_2').val('');
    $('#sale_forsale_2').val(0);
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
    //$('#sale_series_2').val('');
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
    $('#sale_model_2').val('');
    $('.marking-img-2').html('<label for="mobile">打标图片</label><br/>');
    $('#sale_market_price_2').val('');
    $('#sale_price_2').val('');
    $('#sale_use_flg_2').val(1);

    $('#sale_goods_name_2').parent().css('visibility','hidden');
    $('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().css('visibility','hidden');
    $('#sale_sku_2').parent().css('visibility','hidden');
    $('#sale_forsale_2').parent().css('visibility','hidden');
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
    //$('#sale_series_2').parent().css('visibility','hidden');
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
    $('#sale_model_2').parent().css('visibility','hidden');
    $('.marking-img-2').css('visibility','hidden');
    $('#sale_market_price_2').parent().css('visibility','hidden');
    $('#sale_price_2').parent().css('visibility','hidden');
    $('#sale_use_flg_2').parent().css('visibility','hidden');
    $('#sale_source_2').html('');
    $('#sale_source_2').parent().css('visibility','hidden');
}

function setExamineGoodsValue(data){
	var new_data = data.new_data;
	var old_data = data.old_data;
    $('#sale_goods_name').val(new_data['goods_name_cn']);
    $('#examine-goods-sku').find('input[name=sale_product][value='+new_data['sale_product']+']').prop('checked',true);
    $('#sale_sku').val(new_data['sku']);
    $('#sale_forsale').val(new_data['forsale']);
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
    //$('#sale_series').val(new_data['series']);
    //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
    $('#sale_model').val(new_data['model']);
    //add by lizenan 201802101 【商城需求】商品图片上增加图片打标	493	start
    var class_len = $('#class_len').val();
    var div_class = 'dropdown-sin-'+class_len;
    var marking_img_html = '';
    marking_img_html += '<div class="'+div_class+'" style="width: 50%;float:left">';
    marking_img_html += '<select disabled name="marking_img_id">';
    marking_img_html += '<option value="0||0" data-url="">请选择</option>';
    var marking_img_url = '';
    if(mark_img.length > 0){
    	mark_img.forEach(function(e,index){
    		var selected = '';
    		if(parseInt(new_data['marking_img_id']) > 0 && new_data['marking_img_id'] == e.id){
            	selected = 'selected';
            	marking_img_url = e.img_url;
            }
    		marking_img_html += '<option value="'+e.id+'||'+e.img_url+'" '+selected+'>'+e.img_name+'</option>';
    	});
    }
    marking_img_html += '</select>';
    marking_img_html += '</div>';
    marking_img_html += '<div style="width: 40%;float:right"><img class="show-img-btn hide" src=""/></div>';
    $('.marking-img-1').append(marking_img_html);
    if(parseInt(new_data['marking_img_id']) > 0){
    	$('.show-img-btn').removeClass('hide');
		$('.show-img-btn').attr('src',imageBathUrl+marking_img_url);
    }
    $('.'+div_class).dropdown({
        readOnly: true,
        input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
   	});
    class_len++;
    $('#class_len').val(class_len);
    //add by lizenan 201802101 【商城需求】商品图片上增加图片打标	493	end
    $('#sale_market_price').val(new_data['market_price']);
    $('#sale_price').val(new_data['sale_price']);
    $('#sale_use_flg').val(new_data['use_flg']);
    var goods_source_old = [];
    var goods_source = [];
    if(old_data && old_data != '' && old_data != null){
    	if(is_null(old_data['goods_source']) != null && old_data['goods_source'].length > 0){
    		goods_source_old = old_data['goods_source'];
    	}
    }
    if(is_null(new_data['goods_source']) != null && new_data['goods_source'].length > 0){
        goods_source = new_data['goods_source'];
        for (i=0;i<goods_source.length ;i++ ){
        	var html = '';
    		html += '<tr><td><a href="javascript:;" img-url="'+goods_source[i].source_url+'" onclick="showMoreImg2($(this))" class="check_show_img">查看图片</a></td></tr>';
            $('#sale_source').append(html);
    	}
        if(goods_source_old.length > goods_source.length){
    		for (i=0;i<goods_source_old.length-goods_source.length;i++ ){
        		var html = '';
        		html = '<tr style="visibility: hidden;"><td>--</td></tr>'
        		$('#sale_source').append(html);
        	}
       	}
    }else{
    	var html = '';
    	for (i=0;i<goods_source_old.length ;i++ ){
    		html += '<tr style="visibility: hidden;"><td>--</td></tr>'
    	}
    	$('#sale_source').append(html);
    }
    //原始数据
    if(old_data && old_data != '' && old_data != null){
    	if(is_null(old_data['goods_name_cn']) != is_null(new_data['goods_name_cn'])){
        	$('#sale_goods_name_2').val(old_data['goods_name_cn']);
        	$('#sale_goods_name_2').parent().removeAttr('style');
       	}else{
       		$('#sale_goods_name_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['sale_product']) != is_null(new_data['sale_product'])){
    		$('#examine-goods-sku').find('input[name=sale_product_2][value='+old_data['sale_product']+']').prop('checked',true);
    		$('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().removeAttr('style');
       	}else{
       		$('#examine-goods-sku').find('input[name=sale_product_2]').parent().parent().parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['sku']) != is_null(new_data['sku'])){
        	$('#sale_sku_2').val(old_data['sku']);
        	$('#sale_sku_2').parent().removeAttr('style');
       	}else{
       		$('#sale_sku_2').parent().css('visibility','hidden');
       	}
    	if(is_null(old_data['forsale']) != is_null(new_data['forsale'])){
        	$('#sale_forsale_2').val(old_data['forsale']);
        	$('#sale_forsale_2').parent().removeAttr('style');
       	}else{
       		$('#sale_forsale_2').parent().css('visibility','hidden');
       	}
    	//mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  start
//       	if(is_null(old_data['series']) != is_null(new_data['series'])){
//        	$('#sale_series_2').val(old_data['series']);
//        	$('#sale_series_2').parent().removeAttr('style');
//       	}else{
//       		$('#sale_series_2').parent().css('visibility','hidden');
//       	}
        //mod by lizenan 20180119 【后台需求】将原本SKU的系列号转移至商品基础资料维护中   469  end
       	if(is_null(old_data['model']) != is_null(new_data['model'])){
        	$('#sale_model_2').val(old_data['model']);
        	$('#sale_model_2').parent().removeAttr('style');
       	}else{
       		$('#sale_model_2').parent().css('visibility','hidden');
       	}
        //add by lizenan 201802101 【商城需求】商品图片上增加图片打标	493	start
       	if(is_null(old_data['marking_img_id']) != is_null(new_data['marking_img_id'])){
       		var class_len = $('#class_len').val();
            var div_class = 'dropdown-sin-'+class_len;
            var marking_img_html = '';
            marking_img_html += '<div class="'+div_class+'" style="width: 50%;float:left">';
            marking_img_html += '<select disabled name="marking_img_id">';
            marking_img_html += '<option value="0||0" data-url="">请选择</option>';
            var marking_img_url = '';
            if(mark_img.length > 0){
            	mark_img.forEach(function(e,index){
            		var selected = '';
            		if(parseInt(old_data['marking_img_id']) > 0 && old_data['marking_img_id'] == e.id){
                    	selected = 'selected';
                    	marking_img_url = e.img_url;
                    }
            		marking_img_html += '<option value="'+e.id+'||'+e.img_url+'" '+selected+'>'+e.img_name+'</option>';
            	});
            }
            marking_img_html += '</select>';
            marking_img_html += '</div>';
            marking_img_html += '<div style="width: 40%;float:right"><img class="show-img-btn-2 hide" src=""/></div>';
            $('.marking-img-2').append(marking_img_html);
            if(parseInt(old_data['marking_img_id']) > 0){
            	$('.show-img-btn-2').removeClass('hide');
        		$('.show-img-btn-2').attr('src',imageBathUrl+marking_img_url);
            }
            $('.'+div_class).dropdown({
                readOnly: true,
                input: '<input type="text" maxLength="20" placeholder="请输入搜索">'
           	});
            class_len++;
            $('#class_len').val(class_len);
            $('.marking-img-2').removeAttr('style');
       	}else{
       		$('.marking-img-2').css('visibility','hidden');
       	}
        //add by lizenan 201802101 【商城需求】商品图片上增加图片打标	493	end
       	if(is_null(old_data['market_price']) != is_null(new_data['market_price'])){
       		$('#sale_market_price_2').val(old_data['market_price']);
       		$('#sale_market_price_2').parent().removeAttr('style');
       	}else{
       		$('#sale_market_price_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['sale_price']) != is_null(new_data['sale_price'])){
       		$('#sale_price_2').val(old_data['sale_price']);
       		$('#sale_price_2').parent().removeAttr('style');
       	}else{
       		$('#sale_price_2').parent().css('visibility','hidden');
       	}
       	if(is_null(old_data['use_flg']) != is_null(new_data['use_flg'])){
       		$('#sale_use_flg_2').val(old_data['use_flg']);
       		$('#sale_use_flg_2').parent().removeAttr('style');
       	}else{
       		$('#sale_use_flg_2').parent().css('visibility','hidden');
       	}
       	var num = 0;
       	if(goods_source_old.length > 0 || goods_source.length > 0){
            for (i=0;i<goods_source_old.length ;i++ ){
            	var html = '';
                if(!goods_source[i] || goods_source_old[i] && goods_source_old[i].source_url != goods_source[i].source_url){
            		html += '<tr><td><a href="javascript:;" img-url="'+goods_source_old[i].source_url+'" onclick="showMoreImg2($(this))" class="check_show_img">查看图片</a></td></tr>';
                    $('#sale_source_2').append(html);
                    num++;
                }else{
            		html = '<tr><td>相同</td></tr>'
            		$('#sale_source_2').append(html);
                }
        	}
        	if(goods_source.length > goods_source_old.length){
        		for (i=0;i<goods_source.length-goods_source_old.length;i++){
            		var html = '';
            		html = '<tr><td>--</td></tr>'
            		$('#sale_source_2').append(html);
            	}
        		num++;
           	}
        }else{
        	$('#sale_source_2').parent().css('visibility','hidden');
        }
        if(num != 0){
			$('#sale_source_2').parent().removeAttr('style');
        }else{
            $('#sale_source_2').parent().css('visibility','hidden');
        }
    }
    $('#goods_sale_edit_id').val(new_data['id']);
}

function changeExamineStatus(status){
	var id = $('#goods_list_edit_id').val();
	$.post('/goods/examine-goods',{status:status,id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#examine-goods').modal('hide');
                table_list_reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function changeExamineSkuStatus(status){
	var id = $('#goods_sale_edit_id').val();
	$.post('/goods/examine-goods-sku',{status:status,id:id},success,'json');
    return false;
    function success(data){
        if(data.code == 200)
        {
            $.jBox.tip('处理成功', 'success');
            window.setTimeout(function () {
                $('#examine-goods-sku').modal('hide');
                goods_list_reload();
                table_list_reload();
            }, 1000);
        }
        else{
            $.jBox.error(data.val, '错误');
        }
    }
}

function goodsPreview(where,type){
	if(type == 1){
		var id = $(where).parents('#examine-goods').find('#goods_list_edit_id').val();
	}else{
		var id = $(where).parents('#examine-goods-sku').find('#goods_sale_edit_id').val();
	}
	var n = window.open('/goods/goods-preview?id='+id+'&type='+type, '_blank');
}
// , input[name="color_spec_id[]"]
$('input[name="size_spec_id[]"]').on('click',function(){
	var name = $(this).attr('name');
	var error = '已勾选同一规格组类型(颜色)不同分组<br/>的选项';
	if(name == 'size_spec_id[]'){
		var error = '已勾选同一规格组类型(尺寸)不同分组<br/>的选项';
	}
	var i=0,j=0;
	$('input[name="'+name+'"]:checked').each(function(){
		i++;
	});
	if(i > 1){
		$(this).parents('.active').find('input[name="'+name+'"]:checked').each(function(){
			j++;
		});
		if(j == 1){
			$(this).prop('checked',false);
			$.jBox.error(error, '错误');
		}
	}
});

$('#add_sku_form').on("keyup",".search_spec",function(){
	searchSpec();
});

$('.nav-tabs').on('click','li',function(){
	var spec_id = $(this).find('a').attr('href');
	var val=$.trim($('.search_spec').val());
	var spec_list=$(spec_id).children("div");
	if(!$.trim(val)){
		spec_list.removeClass('hide');
	}else{
		spec_list.each(function(){
			$(this).find('label').text().toLowerCase().indexOf(val.toLowerCase())>-1?$(this).removeClass('hide'):$(this).addClass('hide');
		});
	}
});

function searchSpec(){
	var val=$.trim($('.search_spec').val());
	var spec_list=$("#add_sku_form").find(".active").children("div");
	if(!$.trim(val)){
		spec_list.removeClass('hide');
	}else{
		spec_list.each(function(){
			$(this).find('label').text().toLowerCase().indexOf(val.toLowerCase())>-1?$(this).removeClass('hide'):$(this).addClass('hide');
		});
	}
}

$('.spec-class').on('click',function(){
	var spec_val = $(this).val();
	if($(this).prop('checked') == true){
		$(this).parent().parent().find('#spec_title_'+spec_val).prop('disabled',false);
		$(this).parent().parent().find('#spec_title_'+spec_val).removeClass('hide');
		$(this).parent().parent().find('.upload-color-pic').removeClass('hide');
		var spec_color_pic = $(this).parent().parent().find('input[name="spec_color_pic[]"]').val();
		if(is_null(spec_color_pic) != null){
			$(this).parent().parent().find('.show-color-pic').removeClass('hide');
			$(this).parent().parent().find('input[name="spec_color_pic[]"]').removeClass('hide');
		}else{
			$(this).parent().parent().find('.show-color-pic').addClass('hide');
			if($(this).attr('data-type') == 2){
				$(this).parent().parent().append('<input name="spec_color_pic[]" value="" type="hidden">');
			}
		}
	}else{
		$(this).parents('div').find('#spec_title_'+spec_val).prop('disabled',true);
		$(this).parents('div').find('#spec_title_'+spec_val).val('');
		$(this).parents('div').find('#spec_title_'+spec_val).addClass('hide');
		$(this).parent().parent().find('.upload-color-pic').addClass('hide');
		$(this).parent().parent().find('.show-color-pic').addClass('hide');
		$(this).parent().parent().find('input[name="spec_color_pic[]"]').remove();
	}
});